<html>
<head><meta charset="utf-8"><title>Macro to allow people to impl Fn* traits? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html">Macro to allow people to impl Fn* traits?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="237644073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237644073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237644073">(May 06 2021 at 11:43)</a>:</h4>
<p>It seems <code>Fn*</code> traits themselves cannot make any progress before the matter of variadic generics is settled. (Which i think won't happen in a few years time)  Is it possible to create and stablize a macro to allow people to impl these traits themselves for common cases?</p>



<a name="237667309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237667309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237667309">(May 06 2021 at 14:30)</a>:</h4>
<p>Isn't that why we require the <code>Fn(T1, T2, ...)</code> syntax and <code>Fn&lt;(args)&gt;</code> is unstable?</p>



<a name="237667362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237667362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237667362">(May 06 2021 at 14:31)</a>:</h4>
<p>we could allow people to <code>impl Fn(T1, T2) for CustomType</code>, no?</p>



<a name="237667398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237667398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237667398">(May 06 2021 at 14:31)</a>:</h4>
<p>I would guess the problem is more so the "call" method, right? Since that needs to somehow take a variable number of parameters</p>



<a name="237667455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237667455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237667455">(May 06 2021 at 14:31)</a>:</h4>
<p>yeah, true</p>



<a name="237667487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237667487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237667487">(May 06 2021 at 14:31)</a>:</h4>
<p>(We could sidetype the question or decide on <em>some</em> lowering; I don't know that it needs to actually be blocked on variadics stabilizing fully)</p>



<a name="237667539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237667539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237667539">(May 06 2021 at 14:32)</a>:</h4>
<p>last time this was brought up my impression was that the <code>"rust-call"</code> ABI simply needs to be replaced with lang items</p>



<a name="237667576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237667576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237667576">(May 06 2021 at 14:32)</a>:</h4>
<p>I don't really know what this has to do with macros though, tbh</p>



<a name="237688659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237688659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237688659">(May 06 2021 at 16:28)</a>:</h4>
<p>oh, obviously i was inspired by the <code>addr_of</code> stablization to avoid deciding on stablizing <code>&amp;raw const</code> in the near future.</p>



<a name="237688873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237688873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237688873">(May 06 2021 at 16:30)</a>:</h4>
<p>I think as long as we're non-specific about the exact ABI of <code>rust-call</code>, we could probably find a path to stabilizing that exact mechanism without stabilizing variadic generics in general.</p>



<a name="237689987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237689987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237689987">(May 06 2021 at 16:38)</a>:</h4>
<p>I believe <code>rust-call</code> currently supports an arbitrary amount of arguments before the final tuple argument. Do we want to stabilize this or only allow <code>extern "rust-call" fn (self: A, args: (B, C))</code>?</p>



<a name="237690228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237690228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237690228">(May 06 2021 at 16:40)</a>:</h4>
<p>Looks like it only supports exactly zero or one argument before the final tuple argument.</p>



<a name="237690758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237690758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237690758">(May 06 2021 at 16:43)</a>:</h4>
<p>And this works:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">extern</span><span class="w"> </span><span class="s">"rust-call"</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">_</span>: <span class="p">())</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>but this doesn't:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">extern</span><span class="w"> </span><span class="s">"rust-call"</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="bp">self</span>: <span class="kp">&amp;</span><span class="nc">Self</span><span class="p">,</span><span class="w"> </span><span class="n">_</span>: <span class="p">())</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>nor does this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">extern</span><span class="w"> </span><span class="s">"rust-call"</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="bp">self</span>: <span class="nc">Rc</span><span class="o">&lt;</span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">_</span>: <span class="p">())</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="237694488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Macro%20to%20allow%20people%20to%20impl%20Fn%2A%20traits%3F/near/237694488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Macro.20to.20allow.20people.20to.20impl.20Fn*.20traits.3F.html#237694488">(May 06 2021 at 17:07)</a>:</h4>
<p>What are the different unstable pieces, and how much are we concerned about them?</p>
<p>Like are we sad if we can never use variadics in the trait because people are doing <code>impl Fn&lt;(i32,)&gt; for ...</code> for a unary method?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>